﻿using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class ElementTools {
	// === Public =====================================================================================================
	public static ElementTools CreateInstance() {
		var instance = new ElementTools();
		return instance;
	}

	public FieldElement GetElement(FieldElementType type, GameObject go) {
		switch (type) {
			case FieldElementType.Frame:
				return new WallElement(go);
			case FieldElementType.Stone:
				return new WallElement(go);
			case FieldElementType.GreenApple:
				return new GreenAppleElement(go);
			case FieldElementType.RedApple:
				return new RedAppleElement(go);
			default:
				throw new Exception("WTF");
		}
	}

	public bool HasElement(Vector3 position) {
		return GameData.GetInstance.Elements.Any(element => position.Equals(element.Position));
	}

	public List<FieldElement> GetElements(FieldElementType type) {
		return GameData.GetInstance.Elements.Where(fieldElement => fieldElement.FieldElementType.Equals(type)).ToList();
	}
}